﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Windows;
using Sector7.Framework.Core;
using Sector7.Framework.Enums;
using System.Windows.Threading;

namespace Sector7.Framework.DataDictionary
{
    /// <summary>
    /// App.xaml 的交互逻辑
    /// </summary>
    public partial class App : Application
    {
        public App()
        {
            this.Exit += new ExitEventHandler(App_Exit);
            this.DispatcherUnhandledException += new DispatcherUnhandledExceptionEventHandler(App_DispatcherUnhandledException);
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
        }

        void App_Exit(object sender, ExitEventArgs e)
        {
            Log.WriteLine(LogSeverityType.ERR, "DAD", "应用程序退出：退出代码 [{0}]", e.ApplicationExitCode);
        }

        void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
        {
            Log.WriteLine(LogSeverityType.ERR, "DAD", "应用程序异常退出：窗体异常。");
            Log.WriteLine(LogSeverityType.ERR, "DAD", Environment.NewLine);
            Log.WriteLine(LogSeverityType.ERR, "DAD", e.Exception);
        }

        void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            Log.WriteLine(LogSeverityType.ERR, "DAD", "应用程序异常退出：非窗体异常");
            Log.WriteLine(LogSeverityType.ERR, "DAD", Environment.NewLine);
            Log.WriteLine(LogSeverityType.ERR, "DAD", e.ExceptionObject as Exception);
        }
    }
}
